package com.thoughtworks;

public class Restaurant {

  public String bestCharge(String selectedItems) {
    Analysis analyst = new Analysis();
    OriginalPrice originalPrice = new OriginalPrice();
    ThirtyMinusSix thirtyMinusSix = new ThirtyMinusSix();
    HalfPrice halfPrice = new HalfPrice();
    String discountMethod = null;

    String[] ids = analyst.returnIds(selectedItems);
    int[] numbers = analyst.returnNumbers(selectedItems);

    int moneyOriginal = originalPrice.applyDiscounts(ids, numbers);
    int moneyThirty = thirtyMinusSix.applyDiscounts(ids, numbers);
    int moneyHalf = halfPrice.applyDiscounts(ids, numbers);
    int finalPrice = 0;

    if(moneyHalf==moneyThirty) {
      discountMethod = "none";
      finalPrice = moneyOriginal;
    }
    else if(moneyHalf<moneyThirty) {
      discountMethod = "half";
      finalPrice = moneyHalf;
    } else {
      discountMethod = "thirty";
      finalPrice = moneyThirty;
    }

    Render render = new Render(discountMethod, finalPrice, moneyOriginal, ids, numbers);
    String orderDetails = render.renderOrderDetails();

    return orderDetails;
  }
}
